import { Injectable } from '@nestjs/common';
import { CreateAuthDto } from './dto/create-auth.dto';
import { UpdateAuthDto } from './dto/update-auth.dto';
import { UserService } from './../user/user.service'
import { JwtService } from '@nestjs/jwt'

@Injectable()
export class AuthService {
  constructor(private readonly userservice:UserService,private readonly jwtService:JwtService){}

  async signIn(body){
    const userInfo = await this.userservice.findOne(body.username)
    console.log("authService",userInfo)
    const payload = { sub: userInfo.id, username: userInfo.username };
    return {
      ...userInfo,
      access_token: await this.jwtService.signAsync(payload),
    };
  }
}
